import { _decorator, Camera, Color, Component, instantiate, Node, ParticleSystem2D, Prefab, Vec3 } from 'cc';
import { GGResource } from '../../../framework/core/base/GGResource';
import { Block } from '../../../game/src/scripts/Block';
import Config from '../../../utils/Config';
const { ccclass, property } = _decorator;

@ccclass('EffectManager')
export class EffectManager extends Component {
    @property({ type: Node, displayName: "粒子父节点" })
    public particParent: Node = null

    @property({ type: Prefab, displayName: "粒子" })
    public particPre: Prefab = null

    @property({ type: Camera, displayName: "主摄像头" })
    public mainCamera: Camera = null

    protected start(): void {
        GGResource.loadBundle("effect").then(bundle => {
            if (bundle) {
                gg.log ("成功加载特效")
            }
        });
        
    }

    // 在指定位置播放特效
    public showEffectAt(node: Node) {
        // const worldPosition = node.getWorldPosition()
        // const screenPosition = new Vec3()

        // this.mainCamera.convertToUINode(worldPosition, this.particParent, screenPosition)

        
        // const effect = instantiate(this.particPre);
        // effect.parent = this.particParent
        // effect.position = screenPosition

        // var particCom = effect.getComponent(ParticleSystem2D)
        // var block = node.getComponent(Block)

        // particCom.startColor = Config.colors[block.cIndex]
        // particCom.startColorVar = Config.colors[block.cIndex]
        // particCom.endColor = Config.colors[block.cIndex]
        // particCom.endColorVar = Config.colors[block.cIndex]
    }

    private onStopped() {

    }
}


